// 递归
let fib = function (n) {
  if (n <= 2) {
    return 1
  }
  return fib(n - 2) + fib(n - 1)
}

// 尾递归
let fib = function (n, prev = 1, next = 1) {
  if (n <= 2) {
    return next
  }
  return fib(n - 1, next, prev + next)
}

// for循环
let fib = function (n) {
  if (n <= 2) {
    return 1
  }
  let sum = 0
  let prev = 1
  let next = 1
  for (let i = 3; i <= n; i++) {
    sum = prev + next
    prev = next
    next = sum
  }
  return sum
}

console.log(fib(8)) // 21